package reggie.ruiji.mapper;


import org.apache.ibatis.annotations.*;
import reggie.ruiji.Dto.DishDto;
import reggie.ruiji.pojo.Dish;

import java.util.List;
@Mapper
public interface DishMapper {

    @Select("select count(*) from dish where category_id = #{id}")
    public Long countByid (Long id);


    @Insert("insert into dish (name,category_id,price,image,description,status,create_time,update_time,create_user,update_user,code) values (#{name},#{categoryId},#{price},#{image}," +
            "#{description},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser},#{code})")
    public void insert (DishDto dishDto);

    @Select("select id from dish where name = #{name}")
   public Long getid (String name);

    @Results({
            @Result(column = "category_id", property = "categoryId"),
            @Result(column = "update_time", property = "updateTime")
    })
    @Select("select * from dish")
    public List<DishDto> list (String name);

    @Results({
            @Result(column = "category_id", property = "categoryId"),
    })
    @Select("select * from dish where id = #{id}")
    public Dish getById (Long id);


    @Update("update dish set name = #{name},category_id = #{categoryId},price = #{price},image = #{image},description = #{description},status = #{status},update_time = #{updateTime},update_user = #{updateUser},code = #{code} where id = #{id}")
    public void update (DishDto dishDto);

    @Delete("<script>" +
            "delete from dish where id in " +
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            "</script>")
    public void delete(List<Long> ids);


   @Update("<script>" +
           "update dish set status = #{status} where id in " +
           "<foreach collection='ids' item='id' open='(' separator=',' close=')'>" +
           "#{id}" +
           "</foreach>" +
           "</script>")
    public void updateStatus (List<Long> ids, Integer status);


   //只查询起售状态下的
   @Select("select * from dish where category_id = #{categoryId} and status = #{status}")
    public List<DishDto> getDishByCategoryId(Long categoryId,Integer status);



}
